package com.zj.ecology.fragments

import android.widget.ImageView
import cn.bingoogolapple.bgabanner.BGABanner
import com.zj.base.base_fg.BaseFragment
import com.zj.base.base_fg.FragmentObserver
import com.zj.base.base_fg.StateChange
import com.zj.base.list.adapters.BaseAdapter
import com.zj.base.list.holders.BaseViewHolder
import com.zj.base.view_injector.annotantions.IdRes
import com.zj.ecology.utils.ImageLoaderUtils
import com.zj.ecology.R
import com.zj.ecology.interfaces.FragmentDataSet
import com.zj.ecology.module.GalleryInfo
import com.zj.ecology.views.BaseLoopGallery
import com.zj.weather.DynamicWeatherBackground

/**
 * Created by zhaojie on 2018/7/13.
 */

class MainFragments : BaseFragment() {

    @IdRes(R.id.main_frg_banner)
    private val banner: BGABanner? = null

    @IdRes(R.id.main_frg_gallery)
    private val galleryView: BaseLoopGallery<GalleryInfo>? = null

    override fun getLayoutId(): Int {
        return R.layout.fragment_main
    }

    override fun initView() {
        banner?.setAdapter({ banner, view, module, position ->
            view.postDelayed({
                ImageLoaderUtils.loadWithCache(view as ImageView?, module as String?, view.width, view.height)
            }, 300)

        })
        banner?.setOnItemClickListener({ banner, view, module, position ->

        })
        banner?.setAutoPlayAble(true)
        banner?.setAutoPlayInterval(3000)
        var datas = arrayListOf<String>()
        datas.add("http://img0.imgtn.bdimg.com/it/u=1085519096,3271169462&fm=27&gp=0.jpg")
        datas.add("http://img1.imgtn.bdimg.com/it/u=2547964660,2934798817&fm=27&gp=0.jpg")
        datas.add("http://img5.imgtn.bdimg.com/it/u=1477035066,1772020559&fm=27&gp=0.jpg")
        banner?.setData(datas)
        val galleryImages = arrayListOf<GalleryInfo>();
        galleryImages.add(GalleryInfo("https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2423759013,2760269847&fm=27&gp=0.jpg", "asdfa1"))
        galleryImages.add(GalleryInfo("https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2423759013,2760269847&fm=27&gp=0.jpg", "asdfa1"))
        galleryImages.add(GalleryInfo("https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2423759013,2760269847&fm=27&gp=0.jpg", "asdfa1"))
        galleryImages.add(GalleryInfo("https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2423759013,2760269847&fm=27&gp=0.jpg", "asdfa1"))
        galleryImages.add(GalleryInfo("https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2423759013,2760269847&fm=27&gp=0.jpg", "asdfa1"))
        galleryImages.add(GalleryInfo("https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2423759013,2760269847&fm=27&gp=0.jpg", "asdfa1"))
        galleryView?.setGalleryData(object : BaseAdapter<GalleryInfo>(R.layout.item_main_gallery_adapter_layout, galleryImages) {

            override fun initData(holder: BaseViewHolder?, position: Int, module: GalleryInfo?) {
                holder?.setText(R.id.galleryItem_tvTitle, module?.title)
                holder?.setImage(R.id.galleryItem_iv, module?.imgLink)
            }

            override fun getItemCount(): Int {
                return Int.MAX_VALUE
            }

            override fun getItem(position: Int): GalleryInfo {
                return infos[position % infos.size]
            }
        })
    }

    override fun initData() {

    }
}
